﻿namespace Digitalmes.Application.Sys.Users.Queries;

/// <summary>
/// 获取用户信息查询命令。
/// </summary>
public record GetUserQuery(long UserId) : IRequest<IResult<SysUserDto>>;

public sealed class GetUserQueryHandler(IRepository<SysUser> repo) : IRequestHandler<GetUserQuery, IResult<SysUserDto>>
{
    public async Task<IResult<SysUserDto>> Handle(GetUserQuery request, CancellationToken cancellationToken)
    {
        var user = await repo.AsQueryable()
            .Includes(s => s.Org)
            .GetByIdAsync(request.UserId, cancellationToken);
        return Result.From(user.Adapt<SysUserDto>());
    }
}
